package model;

import graphics.SpriteBatch;
import main.Core;

import org.newdawn.slick.Color;
import org.newdawn.slick.UnicodeFont;

import dao.ContentManager;
import data.Vector2;

/**
 * Classe que serve como componente visual de texto.
 * Esta classe ignora "size".
 * @author Ygor
 *
 */
public class TextSprite extends Sprite {
	private UnicodeFont font;
	private String text;
	private Color textColor;
	private int fontSize;
	
	
	public TextSprite(String text, int fontSize, Vector2 pos, GameObject owner, Core core) {
		this("basic", text, fontSize, pos, owner, core);
	}
	public TextSprite(String fontResource, String text, Vector2 pos, GameObject owner, Core core) {
		this(fontResource, text, 20, pos, owner, core);
	}
	public TextSprite(String text, Vector2 pos,  GameObject owner, Core core) {
		this("basic", text, 20, pos, owner, core);
	}
	// construtor real
	public TextSprite(String fontResource, String text, int fontSize, Vector2 pos, GameObject owner, Core core) {
		super(fontResource, pos, Vector2.zero(), owner, core);
		this.setText(text);
		this.fontSize = fontSize;
		this.textColor = Color.black;
	}
	
	@Override
	public void load()
	{
		font = ContentManager.loadFont(getResource(), fontSize);
	}
	
	public void draw(SpriteBatch painter) {
		if (isVisible()) {
			painter.drawText(this);
		}
		super.draw(painter);
	}

	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public int getFontSize() {
		return fontSize;
	}
	public void setFontSize(int fontSize) {
		this.fontSize = fontSize;
		load(); // reload to apply changes.
	}
	public UnicodeFont getFont() {
		return font;
	}
	public Color getTextColor() {
		return textColor;
	}
	public void setTextColor(Color textColor) {
		this.textColor = textColor;
	}	
}
